﻿using System;
using System.Web.UI;
using StockholmsStad.Web.UI.UIServiceReference;

namespace StockholmsStad.Web.UI.Controls
{
    /// <summary>
    /// WebControl för sammanfattningen av bokningen
    /// </summary>
    public partial class BookingSummary : UserControl
    {
        private string TimeText
        {
            get { return lblTime.Text; }
            set
            {
                lblTimeText.Visible = true;
                lblTime.Visible = true;
                lblBookingCodeText.Visible = false;
                lblBookingCode.Visible = false;
                lblTime.Text = value;
            }
        }

        private string BookingCodeText
        {
            get { return lblBookingCode.Text; }
            set
            {
                lblTimeText.Visible = false;
                lblTime.Visible = false;
                lblBookingCodeText.Visible = true;
                lblBookingCode.Visible = true;
                lblBookingCode.Text = value;
            }
        }

        /// <summary>
        /// Körs när sidan laddas
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        /// <summary>
        /// Uppdatera bokningsinformationen på sammanfattningen.
        /// </summary>
        /// <param name="booking"></param>
        /// <param name="GetDateWeekdayText">Funktion för veckodagstext för ett datum</param>
        /// <param name="GetTimeText">Funktion för tidstext för ett datum</param>
        /// <param name="locationName"></param>
        public void UpdateBooking(Booking booking, Func<DateTime, string> GetDateWeekdayText,
                                  Func<DateTime, string> GetTimeText, string locationName)
        {
            if (booking.DateTime != null)
            {
                lblLocation.Text = locationName;
                lblDate.Text = GetDateWeekdayText(booking.DateTime.StartDateTime);
            }
            if (CeremonyType.Ordinary == booking.CeremonyType)
            {
                TimeText = booking.DateTime == null ? "" : GetTimeText(booking.DateTime.StartDateTime);
            }
            else
            {
                BookingCodeText = booking.MinisterCode;
            }
            if (booking.PreferredDate1 != null)
            {
                lblPreferredDate1.Text = GetDateWeekdayText((DateTime) booking.PreferredDate1);
            }
            if (booking.PreferredDate2 != null)
            {
                lblPreferredDate2.Text = GetDateWeekdayText((DateTime) booking.PreferredDate2);
            }
        }
    }
}